package com.gemantic.task.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author ouka
 */
@Component
public class SpringUtils implements ApplicationContextAware {
    private static ApplicationContext myApplicationContext;


    public static <T> T getBean(String beanName, Class<T> clzz) {
        return myApplicationContext.getBean(beanName, clzz);
    }

    public static <T> T getBean(Class<T> clzz) {
        return myApplicationContext.getBean(clzz);
    }

    public static Object getBean(String beanName) {
        return myApplicationContext.getBean(beanName);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        myApplicationContext = applicationContext;
    }

    public static ApplicationContext getMyApplicationContext() {
        return myApplicationContext;
    }

    public static boolean containsBean(String name) {
        return myApplicationContext.containsBean(name);
    }

}
